import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

/**
 * @author: gao
 * @create-date: 2025/4/26 19:45
 */

public class Soluion {
    public int[] asteroidCollision(int[] asteroids) {
        Stack<Integer> stack = new Stack<>();
        for (int i : asteroids) {
            if (i > 0) {
                stack.push(i);
            } else {
                if (stack.isEmpty() || stack.peek() < 0) {
                    stack.push(i);
                } else {
                    while (!stack.isEmpty() && stack.peek() > 0 && stack.peek() < -i) {
                        stack.pop();
                    }
                    if (!stack.isEmpty() && stack.peek() == -i) {
                        stack.pop();
                    } else if (stack.isEmpty() || stack.peek() < 0) {
                        stack.push(i);
                    }
                }
            }
        }
        int[] ret = new int[stack.size()];
        for (int i = ret.length - 1; i >= 0; i--) {
            ret[i] = stack.pop();
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int len = in.nextInt();
            int[] nums = new int[len];
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
            }
            Soluion soluion = new Soluion();
            System.out.println(Arrays.toString(soluion.asteroidCollision(nums)));
        }
    }
}